#include "ItemBlockStateFired.h"




void ItemBlockStateFired::_initSprite()
{
	_sprites = new Sprites(_data->getRect());
	_sprites->addSprite(1, _data->getItemType(), 60);
	_sprites->setState(1);
}

ItemBlockStateFired::ItemBlockStateFired(ItemData* data)
{
	_data = data;
	_data->getRect()->Vx = 2;
	_counter = 0;
	_initSprite();
}

void ItemBlockStateFired::updateData(int action, int action_data)
{
	if (action == ACTIONS_STOP_FLYING) {
		_counter = 10001;
		_data->getRect()->Vx = _data->getRect()->Vy = 0;
	}
	if (action == ACTIONS_HIT_PLAYER) {
		_data->isDead = true;
	}
}

void ItemBlockStateFired::draw(long time)
{
	if (!_data->isDead)
		_sprites->draw();
}

void ItemBlockStateFired::udpate(long time)
{
	_data->type = _data->getItemType();
	_sprites->currentSprite->setIndex(_data->itemRandom - _ID_ITEM_BLOCK);
	updatePhysics(time);
}

void ItemBlockStateFired::updatePhysics(int time)
{
	//if (time % 10 == 0) {
	if (_counter < 10) {
		_data->getRect()->Vy = 6;
	} if (_counter < 40) {
		_data->getRect()->Vy = _data->getRect()->Vy > -8 ? _data->getRect()->Vy - 0.2 : _data->getRect()->Vy;
	} else if (_counter < 1000) {
		_data->getRect()->Vy = _data->getRect()->Vy > -10 ? _data->getRect()->Vy - 0.7 : _data->getRect()->Vy;
	}
	_counter++;
	_data->getRect()->X += _data->getRect()->Vx;
	_data->getRect()->Y += _data->getRect()->Vy;
	//}
}
